package com.sp.system.user.core.producer;

import lombok.extern.slf4j.Slf4j;
import org.apache.activemq.command.ActiveMQQueue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.stereotype.Component;

import javax.jms.Queue;
@Slf4j
@Component
public class QueueProducer {

    @Autowired
    private JmsMessagingTemplate jmsMessagingTemplate;

    @Autowired  //此注解默认是以类型找  在配置文件中 已经注入的  @Bean
    private Queue queue;

    public void sendByQueue(String name) {
        log.debug("点对点通讯，name={{}}",name);
        jmsMessagingTemplate.convertAndSend(queue,name);
    }


    public void sendStringQueue(String queueName, String message) {
        log.debug("点对点通讯，queueName={{}}，message：【{}】",queueName,message);
        this.jmsMessagingTemplate.convertAndSend(new ActiveMQQueue(queueName), message);
    }

}
